#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

typedef struct Account {
    char username[51];
    char password[51];
    char phone[12];
} Account;

void convertPassword(char *password) {
    for (int i = 0; password[i]!= '\0'; i++) {
        if (islower(password[i])) {
            password[i] = toupper(password[i]);
        } else if (isupper(password[i])) {
            password[i] = tolower(password[i]);
        }
    }
}

int main() {
    char phone[12];
    scanf("%s", phone);
    int n;
    scanf("%d", &n);
    Account *accounts = (Account *)malloc(n * sizeof(Account));
    for (int i = 0; i < n; i++) {
        scanf("%s %s %s", accounts[i].username, accounts[i].password, accounts[i].phone);
    }
    int found = 0;
    for (int i = 0; i < n; i++) {
        if (strcmp(accounts[i].phone, phone) == 0) {
            convertPassword(accounts[i].password);
            printf("%s %s\n", accounts[i].username, accounts[i].password);
            found = 1;
        }
    }
    if (!found) {
        printf("empty\n");
    }
    free(accounts);
    return 0;
}
